package com.example.myapplication.ui.Home.fragments;


import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;

import com.example.myapplication.R;
import com.example.myapplication.app.AppConstant;
import com.example.myapplication.base.BaseFragmentAdapter;
import com.example.myapplication.base.BaseMvpFragment;
import com.example.myapplication.model.bean.NewsSummary;
import com.example.myapplication.model.bean.VideoChannelTable;
import com.example.myapplication.presenter.VideoPresenter;
import com.example.myapplication.presenter.contract.VideoContract;
import com.example.myapplication.ui.news.activity.VideosFragment;
import com.example.myapplication.utils.MyUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

public class VideoFragment extends BaseMvpFragment<VideoPresenter> implements VideoContract.View {
    private ArrayList<String> mImageList;

    @BindView(R.id.tabs)
    TabLayout tabs;
    @BindView(R.id.view_pager)
    ViewPager viewPager;
    @BindView(R.id.fab)
    FloatingActionButton fab;
    private BaseFragmentAdapter fragmentAdapter;
    @Override
    protected VideoPresenter initPresenter() {
        return new VideoPresenter(getActivity());
    }
    @Override
    protected int getLayoutId() {
        return R.layout.fragment_vido;
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void initEventAndData() {
        List<String> channelNames = new ArrayList<>();
        List<VideoChannelTable> videoChannelTableList = mPresenter.loadVideosChannelsMine();
        List<Fragment> mNewsFragmentList = new ArrayList<>();
        for (int i = 0; i < videoChannelTableList.size(); i++) {
            channelNames.add(videoChannelTableList.get(i).getChannelName());
            mNewsFragmentList.add(createListFragments(videoChannelTableList.get(i)));
        }
        fragmentAdapter = new BaseFragmentAdapter(getChildFragmentManager(), mNewsFragmentList, channelNames);
        viewPager.setAdapter(fragmentAdapter);
        tabs.setupWithViewPager(viewPager);
        MyUtils.dynamicSetTabLayoutMode(tabs);
    }

    private VideosFragment createListFragments(VideoChannelTable videoChannelTable) {
        VideosFragment fragment = new VideosFragment();
        Bundle bundle = new Bundle();
        bundle.putString(AppConstant.VIDEO_TYPE, videoChannelTable.getChannelId());
        fragment.setArguments(bundle);
        return fragment;
    }
    @Override
    public void showError(String msg) {

    }


    @Override
    public void SuccessRefresh(List<NewsSummary> newsSummaries) {

    }
}
